package cn.toma.core.result;

import java.util.HashMap;

/**
 * @author zqx
 * @version 1.0.0
 * @ClassName ResponseResult.java
 * @Description 响应结果
 * @createTime 2019年08月28日 14:42:00
 */
public class ResponseResult
{
	/**
	 * @return 直接返回成功结果 不带返回数据
	 */
	public static Result getSuccessObj()
	{
		Result result = new Result(CodeMsg.SUCCESS);
		result.setSucceed(true);
		result.setData(new HashMap<String, Object>(16));
		return result;
	}

	public static Result getSuccessObj(CodeMsg codeMsg)
	{
		Result result = new Result(codeMsg);
		result.setSucceed(true);
		result.setData(new HashMap<String, Object>(16));
		return result;
	}

	/**
	 * @param object 结果数据
	 * @return 返回成功code&msg 并把数据返回
	 */
	public static Result getSuccessObj(Object object)
	{
		Result result = new Result(CodeMsg.SUCCESS);
		result.setSucceed(true);
		result.setData(object);

		return result;
	}

	/**
	 * @return 直接返回失败结果 不带返回数据
	 */
	public static Result getFailedObj()
	{
		Result result = new Result(CodeMsg.INTERNAL_SERVER_ERROR);
		result.setSucceed(false);
		result.setData(new HashMap<String, Object>(16));

		return result;
	}

	public static Result getFailedObj(String msg)
	{
		Result result = new Result(CodeMsg.INTERNAL_SERVER_ERROR);
		result.setMsg(msg);
		result.setSucceed(false);
		result.setData(new HashMap<String, Object>(16));

		return result;
	}

	public static Result getFailedObj(CodeMsg codeMsg)
	{
		Result result = new Result(codeMsg);
		result.setSucceed(false);
		result.setData(new HashMap<String, Object>(16));
		return result;
	}

	/**
	 * @param object 结果数据
	 * @return 返回失败code&msg 并把数据返回
	 */
	public static Result getFailedObj(Object object)
	{
		Result result = new Result(CodeMsg.INTERNAL_SERVER_ERROR);
		result.setSucceed(false);
		result.setData(object);
		return result;
	}

	/**
	 * @param code 自定义状态码
	 * @param msg  自定义msg
	 * @return 返回自定义的状态码及msg
	 */
	public static Result getFailedObj(Integer code, String msg)
	{
		Result result = new Result();
		result.setCode(code);
		result.setMsg(msg);
		result.setSucceed(false);
		result.setData(new HashMap<String, Object>(16));
		return result;
	}

}
